/*
 * Project CelestialBeing: singleton.hpp
 * Created: 2023/12/15
 * This program uses MulanPSL2. See LICENSE for more.
 */

#ifndef CELESTIALBEING_SINGLETON_HPP
#define CELESTIALBEING_SINGLETON_HPP

#include "cb/common/celestial_being_base.hpp"
CB_NAMESPACE_BEGIN

// Singleton base class.
// Usage:
// class A : public Singleton<A> {
//     friend class Singleton<A>;
//     A() {}
//     ~A() {}
// };
// A::Get().DoSomething();
template<class T>
class Singleton {
public:
    inline static T & Get () {
        static T instance;
        return instance;
    }
};

CB_NAMESPACE_END

#endif //CELESTIALBEING_SINGLETON_HPP
